package com.ipt.frm.pw;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ipt.frm.pw.bean.Mensaje;
import com.ipt.frm.pw.enumeracion.TipoMensaje;

/**
 * Servlet implementation class LogoutServlet
 */
public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	static Properties propertiesMsg;
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LogoutServlet() {
        super();
    }
    
    @Override
    public void init() throws ServletException {
    	// TODO Auto-generated method stub
    	super.init();
    	
    	propertiesMsg = new Properties();
    	propertiesMsg =(Properties) getServletContext().getAttribute("properties");
    	
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	
	 @Override
	   public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		 
		 HttpSession session = request.getSession();
		 Mensaje mensaje;
		 
		 session.invalidate();
		 mensaje = new Mensaje(TipoMensaje.INFO, propertiesMsg.getProperty("logout.success"));
		 request.setAttribute("tittle", "Login");
		 request.setAttribute("MSG", mensaje);
		 RequestDispatcher dispacher = this.getServletContext().getRequestDispatcher("/login.jsp");
		 dispacher.forward(request, response);
		 
	 
	 }

}
